#-------------------------------------------------------------------------------
# Name:       Client.MAIN_CFG
# Purpose:
#
# Author:      Administrator
#
# Created:     Mar 30, 2013
# Copyright:   (c)Tal Bar-Or 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------

#Import section
import os, sys
import datetime as dt
import pymysql
import configparser

from incalendar.functions import *
from incalendar.Class_def import *
#from incalendar.sql_functions import *

#CHECKING FOR CONFIG SETTINGS

cfgfile = os.getcwd() +'\incconfig.cfg'
config = configparser.ConfigParser()
config.sections()
config.read(cfgfile)
SQL_SERVER = config['MYSQLDB']['SERVER']
SQL_PORT = int(config['MYSQLDB']['PORT'])
SQL_DBNAME = config['MYSQLDB']['DBNAME']
SQL_USER = config['MYSQLDB']['USER']
SQL_PASS = config['MYSQLDB']['PASS']


def dbconnect():
    conn = pymysql.connect(host=SQL_SERVER, port=SQL_PORT, user=SQL_USER, passwd=SQL_PASS, db=SQL_DBNAME)
    #!/usr/bin/env python



    #conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql')



    # print cur.description
    cur.execute("SELECT * FROM person_d")
    r = cur.fetchall()
    print(r)
    # ...or...
    #for r in cur.fetchall():
     #  print (r)

    cur.close()
    conn.close()

def GetPersonDinfo(usrid):
            print(SQL_PORT)
            conn = pymysql.connect(host=SQL_SERVER, port=SQL_PORT, user=SQL_USER, passwd=SQL_PASS, db=SQL_DBNAME)
            cur = conn.cursor()

            cur.callproc("GetPrsnD_info",(usrid))
            cur.execute()
            results = cur.fetchall()


            return(results,type(results))

            # r = cur.fetchall()
            cur.close()
            conn.close()


def main():
    print(SQL_PORT)
    conn = pymysql.connect(host=SQL_SERVER, port=SQL_PORT, user=SQL_USER, passwd=SQL_PASS, db=SQL_DBNAME)
    cur = conn.cursor()
    userid = 1
    #cur.callproc("GetPrsnD_info",(userid))
    cur.execute('CALL GetPrsnD_info({0})'.format(userid))
    #results = cursor.fetchone()
    results = cur.fetchall()
    for x in results:
        print(results,type(results))
    #return(results,type(results))

    # r = cur.fetchall()
    cur.close()
    conn.close()

    #srvconnect()
    #dbconnect()


#def srvconnect():

 #   pass
    #conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='Gfn123', db='incalander')


    #cur = conn.cursor()



if __name__ == '__main__':
    main()



